{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import svm, datasets\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "# Add noisy features\n",
    "random_state = np.random.RandomState(0)\n",
    "n_samples, n_features = X.shape\n",
    "X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]\n",
    "\n",
    "# Limit to the two first classes, and split into training and test\n",
    "X_train, X_test, y_train, y_test = train_test_split(X[y < 2], y[y < 2],\n",
    "                                                    test_size=.5,\n",
    "                                                    random_state=random_state)\n",
    "\n",
    "# Create a simple classifier\n",
    "classifier = svm.LinearSVC(random_state=random_state)\n",
    "classifier.fit(X_train, y_train)\n",
    "y_score = classifier.decision_function(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average precision-recall score: 0.88\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y_test:  (50,)\n",
      "[1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0\n",
      " 0 0 0 1 1 1 1 0 1 1 0 1 0]\n",
      "y_score:  (50,)\n",
      "[-0.20078869  0.30423874  0.20105976  0.27523711  0.42593404 -0.15043726\n",
      " -0.08794601 -0.12733462  0.22931596 -0.23913518 -0.06386267 -0.14958466\n",
      " -0.04914839  0.09898417  0.0515638  -0.1142941   0.16106135  0.04871897\n",
      " -0.08258102 -0.26105668  0.24693291 -0.18029058 -0.38384994  0.26336904\n",
      "  0.12585371 -0.03991278  0.39424539  0.42411536 -0.4790443  -0.30529061\n",
      " -0.09281931  0.01213433 -0.20204098  0.40148935 -0.04536122  0.12179099\n",
      "  0.06493837 -0.07007139  0.0032915  -0.39635676  0.02619439  0.20018683\n",
      "  0.065023    0.49589616 -0.28221895  0.31364573  0.1906223   0.11549516\n",
      "  0.03145977  0.22408591]\n"
     ]
    }
   ],
   "source": [
    "print(\"y_test: \", y_test.shape)\n",
    "print(y_test)\n",
    "\n",
    "print(\"y_score: \", y_score.shape)\n",
    "print(y_score)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def apScore(y_test, y_score):\n",
    "    from sklearn.metrics import average_precision_score\n",
    "    average_precision = average_precision_score(y_test, y_score)\n",
    "\n",
    "    print('Average precision-recall score: {0:0.2f}'.format(\n",
    "          average_precision))\n",
    "    return average_precision\n",
    "    \n",
    "def plotAP(y_test, y_score):\n",
    "    from sklearn.metrics import precision_recall_curve\n",
    "    import matplotlib.pyplot as plt\n",
    "    from sklearn.utils.fixes import signature\n",
    "\n",
    "    average_precision = apScore(y_test, y_score)\n",
    "    precision, recall, _ = precision_recall_curve(y_test, y_score)\n",
    "    \n",
    "    \n",
    "    # In matplotlib < 1.5, plt.fill_between does not have a 'step' argument\n",
    "    step_kwargs = ({'step': 'post'}\n",
    "                   if 'step' in signature(plt.fill_between).parameters\n",
    "                   else {})\n",
    "    plt.step(recall, precision, color='b', alpha=0.2,\n",
    "             where='post')\n",
    "    plt.fill_between(recall, precision, alpha=0.2, color='b', **step_kwargs)\n",
    "\n",
    "    plt.xlabel('Recall')\n",
    "    plt.ylabel('Precision')\n",
    "    plt.ylim([0.0, 1.05])\n",
    "    plt.xlim([0.0, 1.0])\n",
    "    plt.title('2-class Precision-Recall curve: AP={0:0.2f}'.format(\n",
    "              average_precision))\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average precision-recall score: 0.83\n"
     ]
    },
    {
     "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k4EtJrqEZg129jR7QHuR5sQlYXVX3VtV3gKtogmNbM0hfnAicA1BVXwV2ApbMS3XjZaD3k37jGhSe/mOLafsiyUHAB2lCYlsdh4Zp+qKqNlfVkqpaXlXLaY7XHF1Vsz4Z2hgb5DXyGZq9CZIsoRmKuno+i5wng/TFd4HnAiR5Ak1Q3DCvVY6H1cAr2k8/HQJsrqrvTXejsRx6quGd/mOrM2BfvAPYBTi3PZ7/3ao6emRFD8mAfbFdGLAvzgcOT3I58GPgdVW1ze11D9gXrwH+Jsl/ozmwfcK2uGGZ5BM0GwdL2uMxbwJ2AKiqD9AcnzkK2ADcAfzmQOvdBvtKkjSHxnXoSZI0JgwKSVIng0KS1MmgkCR1MigkSZ0MCqlPkh8nuSTJt5L8fZLd5nj9JyR5b3t9VZLXzuX6pblmUEgPdmdVPbWqnkTzHZ3fH3VB0igZFFK3r9Jz0rQkr0uyrj2X/5t75r+infeNJGe2817Q/lbKxUk+n+SRI6hf+qmN5TezpXGQZAHNaR9Ob6cPpzlX0sE05/NfneTZNOcY+zPgv1TVjUl2b1fxFeCQqqokvw28nuYbwtJWxaCQHuxhSS6h2ZO4Avindv7h7eXidnoXmuB4CnBuVd0IUFUTvwewF/DJ9nz/OwLfmZ/ypbnl0JP0YHdW1VOBfWj2HCaOUQR4a3v84qlV9biqOr1jPf8HeG9VPRn4HZoT0UlbHYNCmkL7q4F/CLymPZX9+cBvJdkFIMnSJHsCXwR+Pckj2vkTQ0+L2XIK51cibaUcepI6VNXFSS4FjquqM9tTVH+1PUvvbcDx7ZlK3wJcmOTHNENTJ9D8qtq5SW6mCZPHjOIxSD8tzx4rSerk0JMkqZNBIUnqZFBIkjoZFJKkTgaFJKmTQSFJ6mRQSJI6/X82OnJ8aGj5FQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "from sklearn.metrics import average_precision_score\n",
    "y_true = np.array([0, 0, 1, 1])\n",
    "y_scores = np.array([0.1, 0.4, 0.35, 0.8])\n",
    "average_precision_score(y_true, y_scores) \n",
    "plotAP(y_true, y_scores)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py36_pytorch",
   "language": "python",
   "name": "py36_pytorch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
